<template>
    <div class="x-select">
        <div @click="onClickEvent" class="select-ctx">
            <span class="ctx-name">{{name}}</span>
            <span class="iconfont icon-arrow"></span>
        </div>
        <div v-if="isShowList" class="select-list">
            <div @click="selectItem(item.enumName,item.id,index)" v-for="(item,index) in listItem" :key="index" class="list-item">{{item.enumName}}</div>
        </div>
    </div>
</template>
<script>
export default {
    name:"xselect",
    props:{
        listItem:{
            type:Array,
            default:()=>{
                return []
            }
        },
        name:{
            type:String,
            default:""
        }
    },
    data(){
        return{
            isShowList:false
        }
    },
    methods:{
        //点击
        onClickEvent(){
            this.isShowList = !this.isShowList
        },
        //选择item
        selectItem(name,id,index){
            this.isShowList = false
            let tmpname = index==0?name:name
            this.$emit("selectItem",tmpname,id)
        }
    }
}
</script>
<style lang="less" scoped>
.x-select{
    width: 100%;
    height: 100%;
    background: #06121D;
    border: 1px solid rgba(62,178,215,0.00);
    border-radius: 4px;
    position: relative;
    .select-ctx{
        background: transparent;
        padding:0 14px;
        box-sizing: border-box;
        display: flex;
        font-size: 14px;
        color: #fff;
        width: 100%;
        height: 100%;
        box-sizing: border-box;
        display: flex;
        justify-content: space-between;
        align-items: center;
        .ctx-name{
            width: calc(100% - 20px);
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            word-break: normal;
            text-align: left;
        }
        .iconfont{
            width: 20px;
            text-align: right;
            font-size: 14px;
            color: #fff;
            font-weight: 600;
        }
    }
    .select-list{
        z-index: 100;
        position: absolute;
        top: 40px;
        background: #06121D;
        border: 1px solid rgba(62,178,215,0.00);
        border-radius: 4px;
        width: 100%;
        height: 128px;
        overflow-y: auto;
        padding:0 14px;
        box-sizing: border-box;
        .list-item{
            width: 100%;
            height: 32px;
            line-height: 32px;
            font-size: 14px;
            cursor: pointer;
            color: #fff;
            white-space: nowrap;
            word-break: normal;
            text-overflow: ellipsis;
            text-align: left;
            &:not(:last-child){
                border-bottom: 1px dashed #fff;
            }
        }
    }
    .select-list::-webkit-scrollbar {
    width: 2px;
    height: 16px;
    background-color: #ccc;

    }
    // .select-list::-webkit-scrollbar-track{
    //   -webkit-box-shadow:inset 0 0 6px rgba(0,0,0,0.3);
    //   border-radius:10px;
    //   background-color:#fff;
    // }
    .select-list::-webkit-scrollbar-thumb{
          border-radius:10px;
          -webkit-box-shadow:inset 0 0 6px rgba(0,0,0,0.3);
          background-color:rgb(105, 211, 218);
      }
}
</style>

